package com.yimi.yinhepda.views.login.presenter;

import android.Manifest;
import android.app.Activity;
import android.content.pm.PackageManager;
import android.os.Build;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;

import com.yimi.yinhepda.base.BasePresenter;
import com.yimi.yinhepda.views.login.activity.LoginActivity;
import com.yimi.yinhepda.views.login.contract.LoginContract;
import com.yimi.yinhepda.views.login.logic.LoginLogic;

/**
 * @author 000432
 */

public class LoginPresenter extends BasePresenter<LoginContract.LoginView, LoginContract.LoginBiz> implements LoginContract.LoginPresenter {

    @Override
    public LoginContract.LoginBiz createLogic() {
        return new LoginLogic(this);
    }

    @Override
    public void checkNetworkTime(String mCompanyCode, String mEmpCode, String mPwd,String captcha,boolean needVcode) {
        getLogic().checkNetworkTime(mCompanyCode, mEmpCode, mPwd,captcha,needVcode);
    }

    @Override
    public void requestHardwareFlagPermission() {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            if (ContextCompat.checkSelfPermission(getContext(), Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED ||
                    ContextCompat.checkSelfPermission(getContext(), Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
                ActivityCompat.requestPermissions((Activity) getContext(), new String[]{Manifest.permission.ACCESS_FINE_LOCATION,
                                Manifest.permission.ACCESS_COARSE_LOCATION},
                        0);
            }
        }
    }

    @Override
    public void requestInstallPackages() {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            if (ContextCompat.checkSelfPermission(getContext(), Manifest.permission.REQUEST_INSTALL_PACKAGES) != PackageManager.PERMISSION_GRANTED) {
                ActivityCompat.requestPermissions((Activity) getContext(), new String[]{Manifest.permission.REQUEST_INSTALL_PACKAGES},
                        LoginActivity.RQUEST_INSTALL_PACKAGES);
            }
        }
    }
}
